package org.qufenqi.api.controller.front;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.qufenqi.api.common.CommonResponse;
import org.qufenqi.api.entity.Item;
import org.qufenqi.api.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Controller
@RequestMapping("file")
public class FileController {

    @Autowired
    private FileService fileService;

    @PostMapping("uploadUserPicture")
    @ResponseBody
    public CommonResponse<Object> UploadUserPicture(@RequestParam("userid")int userId,@RequestParam("file")MultipartFile file){
        return fileService.UploadUserPicture(userId,file);
    }

    @PostMapping("getUserPicture")
    @ResponseBody
    public CommonResponse<String> GetUserPicture(@RequestBody String UserInfo){
        JSONObject jsonObject = JSON.parseObject(UserInfo);
        int userId = jsonObject.getIntValue("userid");
        String userName = jsonObject.getString("username");

        return fileService.GetUserPicture(userId,userName);
    }


    //上传item图片用
    @PostMapping("itemPictureUpload")
    @ResponseBody
    public CommonResponse<String> itemPictureUpload(@RequestParam String itemsort,@RequestParam String productid,@RequestParam MultipartFile file){
        return fileService.itemPictureUpload(itemsort,productid,file);
    }

}
